<?php

/**
 * @author GallerySoft.info
 * @copyright 2013
 */
// 
// register_sidebars(1, array(
//	'name'          => sprintf( __( 'sidebar_Movie' ), $i ),
//	'id'            => "sidebar-$i",
//	'description'   => '',
//	'class'         => '',
//	'before_widget' => '<li id="%1$s" class="widget %2$s">',
//	'after_widget'  => "</li>n",
//	'before_title'  => '<h2 class="widgettitle">',
//	'after_title'   => "</h2>n",
//));
//

class movie_widget extends WP_Widget{
    public function __construct(){
        parent::__construct('movie_widget', $name=__('Optionated Widget'));
    }
    
    public function widget($args, $instance){
        echo $args['before_widget'];
        echo $args['before_title'];
        echo $instance['title'];
        echo $args['after_title'];
        $args = array(
            'posts_per_page' => $instance['list_count'],
            'post_type' => 'Movie',            
            );
            $query = new WP_Query($args);
            while($query->have_posts()):$query->the_post();
            echo the_title().'<br/>';
            endwhile;
            if($instance['bullets'] == 'true'){
                echo 'Yes!';
            }
            else if($instance['bullets'] == 'false'){
                echo 'None!';
            }
            echo $args['after_widget'];
            echo '</div>';
    }
    
    public function form($instance){
        $title = '';
        $list_count = 1;
        $background = '4b4b4b';
        $container_padding = '10px';
        if(isset($instance['title'])){
            $title = $instance['title'];
        }
        else{
            $title = __('Optionated Widget');
        }
        if(isset($instance['bullets'])){
            $bullets = $instance['bullets'];
        }
        
        echo '<label for="'.$this->get_field_id('title').'">'.__('Widget Title: ').'</label>';
        echo '<input class="widefat" id="'.$this->get_field_name('title').'"type="text" name="'.$this->get_field_name('title').'"';
        
        echo '<label for="'.$this->get_field_id('list_count').'">'.__('how many should be list?: ').'</label>';
        echo '<input id="'.$this->get_field_name('list_count').'"type="text" name="'.$this->get_field_name('list_count').'"';
        
        echo '<label for="'.$this->get_field_id('bullets').'">'.__('Should bullets be displayed: ').'</label>';
        echo '<select name="'.$this->get_field_name('bullets').'" id="'.$this->get_field_name('bullets').'" class="widefat">';
             $option = array('true', 'false');
             foreach($option as $option){
                echo '<option value="'.$option.'" id="'.$option.'"', $bullets==$option?'seclect="selected"':'','>';
             }
             echo '</selected>';
    }
    
    public function update($new_instance, $old_instance){
        $instance['title'] = strip_tags($new_instance['title']);
        $instance['list_count'] = strip_tags($new_instance['list_count']);
        $instance['bullets'] = strip_tags($new_instance['bullets']);
        return $instance;
    } 
}

add_action('widgets_init', function(){
    register_widget(1, 'movie_widget');
})

?>
